package cn.wolfcode.wolf2w.common.sms.config;

import cn.wolfcode.wolf2w.common.sms.service.impl.AliyunSmsServiceImpl;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
@ConditionalOnProperty(prefix = "aliyun.sms",name = {"accessKeyId","accessKeySecret","signName","templateCode","smsFromArea"})
public class SmsAliyunAutoConfiguration {
    // 注解@ConditionalOnProperty加载了nacos中travel-auth-dev.yml内前缀为aliyun.sms的信息，并把name中对应字段的数据加载到配置类里，从而实现配置类数据的低耦合，例如使用的阿里云秘钥或签名变了，可以直接在nacos里的travel-auth-dev.yml内修改而不需要重启服务
    @Bean
    @ConfigurationProperties(prefix = "aliyun.sms")
    public SmsAliyunProperties smsAliyunProperties(){
        return new SmsAliyunProperties();
    }

    @Bean
    @Qualifier("aliyun")
    @Primary
    public AliyunSmsServiceImpl aliyunSmsServiceImpl(){
        return new AliyunSmsServiceImpl();
    }
}
